import { defineStore } from "pinia";
import { store } from "../index";
export const userStore = defineStore({
	id: "app-user",
	state: () => ({
		userInfo: {},
		token: "",
		lastUpdateTime: 0,
	}),
	getters: {
		getUserInfo(): Object {
			return this.userInfo || {};
		},
		getToken(): string {
			return this.token;
		},
	},
	actions: {
		setUserInfo(info: Object) {
			this.userInfo = info;
			this.lastUpdateTime = new Date().getTime();
		},
		setToken(info: string | undefined) {
			this.token = info ? info : "";
		},
	},
});
// 导出外部使用
export function useUserStore() {
	return userStore(store);
}
